Avoid mid-word splits in replace text transform - #2050
Merged
Conversation
🦋 Changeset detectedLatest commit: 9a7e1e7 The changes in this PR will be included in the next version bump. This PR includes changesets to release 37 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Resolve Unicode case-equivalent matches by their originating entry and keep transformed output out of source prefix holdback so later chunks cannot cascade. Co-authored-by: Cursor <cursoragent@cursor.com>
toubatbrian
approved these changes
Jul 17, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Ports livekit/agents#6439 to
agents-jsby changingtextTransforms.replaceto retain only unresolved source text that is a trailing replacement-key prefix. Ordinary unmatched text emits immediately without transform-created mid-word splits.The JS adaptation also fixes two source-inherited defects required by the stated single-pass contract:
undefined.Source diff coverage
Coverage classification
livekit-agents/livekit/agents/voice/transcription/text_transforms.pyagents/src/voice/transcription/text_transforms.tstests/test_transcription_filter.pyagents/src/voice/transcription/text_transforms.test.tsThe equivalent Unicode and replacement-provenance corrections should be applied upstream in Python.
Verification
pnpm exec vitest run agents/src/voice/transcription/text_transforms.test.ts— 23 passed.pnpm --filter @livekit/agents typecheck.pnpm --filter @livekit/agents build.pnpm --filter @livekit/agents lint— exits 0 with existing warnings.pnpm format:check.pnpm build— 38/38 tasks successful.export * as ___syntax; this implementation/test-only repair changes no API surface.Cue voice E2E
Verified exact commit
9a7e1e7844c58a0f255cd941490f12c087c00688in fresh Cue voice mode through the actual sessionttsTextTransformspath, with a transparent transformed-input probe forwarding to real Cartesia TTS.sid_a38b0f06a84d.['you connect.']produced exactly['you connect.'].['visit Live', 'Kit now']produced exactly['visit ', 'Lyve Kit now'].['AſB']produced exactly['AessB'], neverundefined.events.jsonl, command result JSON, three per-command WAVs, and the session WAV. Both channels contain non-zero audio.Ported from livekit/agents#6439
Original PR description
replaceheld back a fixedmax(len(key)) - 1trailing characters on every chunk to catch keys split across streaming boundaries, so ordinary words were emitted split mid-word (e.g. "connect." arrived as "conne" + "ct.").It now buffers only a trailing run that could still start a replacement key and forwards the rest immediately. Substitution uses a single compiled alternation, which also avoids cascading replacements and prefers the longest match on overlapping keys.